package com.aboverock.module.system.databind;

import java.io.IOException;

import org.apache.commons.lang3.StringUtils;

import com.aboverock.module.system.utils.UserInfoUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * The Class UserTypeSerializer.
 *
 * @author Rock Wang
 */
public class UserTypeSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String loginName, JsonGenerator gen, SerializerProvider serializers)
            throws IOException {
        gen.writeString(
                StringUtils.substringBefore(loginName, UserInfoUtil.LOCAL_USER_LOGIN_NAME_SUFFIX));
    }
}
